<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改大师工艺</title>
<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" id="saveAndUpdateFrom" target="_parent" action="">
			<input type="hidden" id="rowId" name="rowId" value='<%=request.getParameter("rowId")%>'/>
			<input type="hidden" id="isReCommit" value="0">
			<input type="hidden" id="token" name="token" value="">
			<div class="form-group">
				<label class="col-xs-2 text-right">大师工艺:</label>
				<div class="col-xs-4">
					<input type="text" class="form-control" name="masterCraft" id="masterCraft" value=""  placeholder="请输入大师工艺">
				</div>
				<label class="col-xs-2 text-right">大师等级:</label>
				<div class="col-xs-4">
					<input type="text" class="form-control" name="masterLevel" id="masterLevel" value=""  placeholder="请输入大师等级">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">词缀类型:</label>
				<div class="col-xs-4">
					<sk:select cssClass="form-control select" id="affixType" name="affixType" value="">
						<option value="">请选择</option>
						<option value="0">前缀</option>
						<option value="1">后缀</option>
					</sk:select>
				</div>
				<label class="col-xs-2 text-right">词缀属性:</label>
				<div class="col-xs-4">
					<input type="text" class="form-control" name="affixProperty" id="affixProperty" value=""  placeholder="请输入词缀属性">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">物品等级:</label>
				<div class="col-xs-4">
					<input type="text" class="form-control" name="goodsLevel" id="goodsLevel" value=""  placeholder="请输入物品等级">
				</div>
				<label class="col-xs-2 text-right">价格:</label>
				<div class="col-xs-4">
					<input type="text" class="form-control" name="price" id="price" value=""  placeholder="请输入价格">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">装备类型:</label>
                <div class="col-xs-4">
                    <sk:select cssClass="form-control select" id="equipParentId" name="equipParentId" value="" requiredInit="true" ajaxURL="${userInfoV1}/gameGoodsType/typeSelect?wm[TYPE_FLAG]=11" onchange="TagUtil.fillOptions('equipParentId')">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" id="equipParentName" name="equipParentName" value="">
                </div>
                <label class="col-xs-2 text-right">装备分类:</label>
                <div class="col-xs-4">
                    <sk:select cssClass="form-control select" id="equipTypeId" name="equipTypeId" value="" parentCascadedSelect="equipParentId" parentParamName="parentId" requiredInit="true" ajaxURL="${userInfoV1}/gameGoodsType/smallTypeSelect?wm[TYPE_FLAG]=11">
                        <option id="equipTypeEle" value="">请选择</option>
                    </sk:select>
                    <input type="hidden" id="equipType" name="equipType" value="">
                </div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">是否开启:</label>
				<div class="col-xs-7">
					<td colspan="2">
						<label><input name="openFlag" type="radio" checked="checked"  value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<label><input name="openFlag" type="radio"  value="0"/>&nbsp;否</label>
					</td>
				</div>
			</div>
		</sk:form>
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script>
    var gameEquipMasterId = $("#rowId").val();//大师工艺ID
    $(function(){
        //后台登录用户token
        $("#token").val(sessionStorage.getItem("token"));
        //修改大师工艺时获取数据
        if(gameEquipMasterId > 0){
            $.ajax({
                url: "${userInfoV1}/gameEquipMaster/getGameEquipMasterInfo",
                type: "post",
                cache: false,
                data:{"rowId":gameEquipMasterId},
                dataType:"json",
                async:false,
                success: function(data) {
                    if (data == null) {
                        return;
                    }
                    $("#masterCraft").val(data.masterCraft);
                    $("#affixType").val(data.affixType);
                    $("#affixProperty").val(data.affixProperty);
                    $("#goodsLevel").val(data.goodsLevel);
                    $("#masterLevel").val(data.masterLevel);
                    $("#price").val(data.price);
                    $("#equipParentId").val(data.equipParentId);
                    $("#equipParentName").val(data.equipParentName);
                    TagUtil.fillOptions('equipParentId');
                    $("#equipTypeId").val(data.equipTypeId);
                    $("#equipType").val(data.equipType);
                    $("input[name='openFlag']").each(function(){
                        if (data.openFlag == $(this).val()) {
                            $(this).attr("checked",true);
                        } else {
                            $(this).attr("checked",false);
                        }
                    });
                }
            });
        }
    });
    var err = {'1':'添加','2':'修改'};
    var action = {'1': '${userInfoV1}/gameEquipMaster/save','2': '${userInfoV1}/gameEquipMaster/update'};
    function add(){
        var rowId = $('#rowId').val();
        var opera;
        if (!CheckUtil.isNotNull(rowId) || rowId <= 0) {
            opera = 1;//添加
        } else {
            opera = 2;//修改
        }
        var masterCraft = $("#masterCraft").val();
        if (!CheckUtil.isNotNull(masterCraft)) {
            layer.msg("请输入大师工艺!");
            return;
        }
        var affixType = $("#affixType").val();
        if (!CheckUtil.isNotNull(affixType)) {
            layer.msg("请选择词缀类型!");
            return;
        }
        var affixProperty = $("#affixProperty").val();
        if (!CheckUtil.isNotNull(affixProperty)) {
            layer.msg("请输入词缀属性!");
            return;
        }
        var goodsLevel = $("#goodsLevel").val();
        if (!CheckUtil.isNotNull(goodsLevel) || !CheckUtil.isInt(goodsLevel, "+")) {
            layer.msg("请输入正确的物品等级!");
            return;
        }
        var masterLevel = $("#masterLevel").val();
        if (!CheckUtil.isNotNull(masterLevel) || !CheckUtil.isInt(masterLevel, "+")) {
            layer.msg("请输入正确的大师等级!");
            return;
        }
        var price = $("#price").val();
        if (!CheckUtil.isNotNull(price)) {
            layer.msg("请输入价格!");
            return;
        }
        var equipParentId = $("#equipParentId").val();
        if (!CheckUtil.isNotNull(equipParentId)) {
            layer.msg("请选择装备类型!");
            return;
        }
        $("#equipParentName").val($("#equipParentId option:selected").text());
        
        var equipTypeId = $("#equipTypeId").val();
        if (!CheckUtil.isNotNull(equipTypeId)) {
            layer.msg("请选择装备分类!");
            return;
        }
        $("#equipType").val($("#equipTypeId option:selected").text());
        
        var openFlag =$('input:radio[name="openFlag"]:checked').val();
        if (!CheckUtil.isNotNull(openFlag)) {
            layer.msg("请选择是否开启!");
            return;
        }
        if ($("#isReCommit").val() == 0) {
            $("#isReCommit").val(1);
            //loading层
            var index = layer.load(0, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: action[opera],
                type: "post",
                cache: false,
                data: new FormData($("#saveAndUpdateFrom")[0]),
                dataType:"json",
                processData: false,
                contentType: false,
                async:false,
                success: function(data) {
                    layer.close(index);
                    if(data.code == 0){
                        parent.layer.msg("添加成功！");
                    } else if(data.code == 1){
                        parent.layer.msg("修改成功！");
                    } else if(data.code == "-2"){
                        parent.window.location.href="${sysManagerV1}/";
                    } else {
                        parent.layer.msg(data.message);
                    }
                    if(data.code >= 0){
                        parent.findData();
                        parent.layer.close(parent.tableIndex);
                    }
                }
            });
        }
    }
</script>
</html>